package com.hs.jhzd.config.mq;

import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import com.hs.jhzd.config.MqCondition;
import com.hs.jhzd.utils.JsonMessageConverter;

@Configuration
@Conditional(MqCondition.class)
public class RabbitTemplateConfiguration {

  @Bean(name = "noticeRabbitTemplate")
  public RabbitTemplate alarmNoticeRabbitTemplate(
      @Qualifier("defaultConnectionFactory") ConnectionFactory connectionFactory) {

    RabbitTemplate template = new RabbitTemplate();
    template.setConnectionFactory(connectionFactory);
    template.setExchange("notice");
    template.setMessageConverter(new JsonMessageConverter());
    return template;
  }

  @Bean
  public TopicExchange noticeExchange() {
    return new TopicExchange("notice", false, false);
  }

  @Bean
  public TopicExchange talkExchange() {
    return new TopicExchange("talk", false, false);
  }

  @Bean
  public TopicExchange talkStatusExchange() {
    return new TopicExchange("talk.status", false, false);
  }
}
